/*
1、地址从E_add_start设计开始，连续存储
2、校验放在最后一位，保证参数正确，验证码不正确则恢复出厂设置
3、字符类参数会用uchar存储一个长度信息
4、增加一个非字符串类参数，需要增加地址、默认值
5、字符串类参数需要增加地址、长度、默认值
6、系统运行数据与设置参数分区存档
*/

//eeprom地址
const unsigned char eeprom_check_code             = 213;                          //检验码
int E_output_current_limit                        = 0;                            //输出电流限制
int E_system_bat_maxv                             = 0;                            //电池最大电压
int E_system_bat_minv                             = 0;                            //电池最小电压
int E_system_bat_protectv                         = 0;                            //电池保护电压
int E_system_bat_current_limit                    = 0;                            //电池充电及输出电流限制
int E_system_internet_mode                        = 0;                            //0-离线模式，1-MQTT模式，2-Blinker模式
int E_system_output_control_mode                  = 0;                            //0-普通模式，1-光控模式，2-光控+时控
int E_system_output_optical_control_time          = 0;                            //光控+时控时打开时间
int E_system_lcd_backlight_time                   = 0;                            //0-常开，1-3分钟，2-5分钟，3-10分钟，4-15分钟，5-30分钟
int E_system_fan_fanOpen_TEM                      = 0;                            //风扇启动温度
int E_system_protect_TEM                          = 0;                            //系统保护温度
int E_system_enable_OTA                           = 0;                            //OTA开关，0-关，1-开
int E_system_output_state                         = 0;                            //输出开关状态，0-开，1-关
int E_system_ina_resistor_1                       = 0;                            //输入采样电阻
int E_system_ina_resistor_2                       = 0;                            //电池采样电阻
int E_system_ina_resistor_3                       = 0;                            //输出采样电阻
int E_mqtt_server_port                            = 0;                            //MQTT服务端口号
int E_system_uart_print_state                     = 0;                            //串口输出状态信息
int E_wifi_ssid_size                              = 0;                            //wifi名称长度
int E_wifi_psd_size                               = 0;                            //wifi密码长度
int E_blinker_auth_size                           = 0;                            //Blinker密钥长度
int E_mqtt_server_add_size                        = 0;                            //MQTT地址长度
int E_mqtt_usr_size                               = 0;                            //MQTT用户名长度
int E_mqtt_psd_size                               = 0;                            //MQTT登录密码长度
int E_system_ota_usr_size                         = 0;                            //OTA用户名长度
int E_system_ota_psd_size                         = 0;                            //OTA密码长度
int E_wifi_ssid                                   = 0;                            //wifi名称
int E_wifi_psd                                    = 0;                            //wifi密码
int E_blinker_auth                                = 0;                            //Blinker密钥
int E_mqtt_server_add                             = 0;                            //MQTT地址
int E_mqtt_usr                                    = 0;                            //MQTT用户名
int E_mqtt_psd                                    = 0;                            //MQTT密码
int E_system_ota_usr                              = 0;                            //OTA用户名
int E_system_ota_psd                              = 0;                            //OTA密码
int E_system_bat_fullv                            = 0;                            //电池满电电压
int E_check_code                                  = 0;                            //检验码地址放在最后


unsigned char wifi_ssid_size                      = 0;                            //WIFI名称长度
unsigned char wifi_psd_size                       = 0;                            //WIFI密码长度
unsigned char blinker_auth_size                   = 0;                            //Blinker密钥长度
unsigned char mqtt_server_add_size                = 0;                            //MQTT服务地址长度
unsigned char mqtt_usr_size                       = 0;                            //MQTT用户名长度
unsigned char mqtt_psd_size                       = 0;                            //MQTT密码长度
unsigned char system_ota_usr_size                 = 0;                            //OTA用户名长度
unsigned char system_ota_psd_size                 = 0;                            //OTA密码长度

//刷新地址
void refreshAddress(char rcd){
  E_output_current_limit                        = E_add_start;                                                          //输出电流限制
  E_system_bat_maxv                             = E_output_current_limit + sizeof(float);                               //电池最大电压
  E_system_bat_minv                             = E_system_bat_maxv + sizeof(float);                                    //电池最小电压
  E_system_bat_protectv                         = E_system_bat_minv + sizeof(float);                                    //电池保护电压
  E_system_bat_current_limit                    = E_system_bat_protectv + sizeof(float);                                //电池充电及输出电流限制
  E_system_internet_mode                        = E_system_bat_current_limit + sizeof(float);                           //0-离线模式，1-MQTT模式，2-Blinker模式
  E_system_output_control_mode                  = E_system_internet_mode + sizeof(unsigned char);                       //0-普通模式，1-光控模式，2-光控+时控
  E_system_output_optical_control_time          = E_system_output_control_mode + sizeof(unsigned char);                 //光控+时控时打开时间
  E_system_lcd_backlight_time                   = E_system_output_optical_control_time + sizeof(unsigned char);         //0-常开，1-3分钟，2-5分钟，3-10分钟，4-15分钟，5-30分钟
  E_system_fan_fanOpen_TEM                      = E_system_lcd_backlight_time + sizeof(unsigned char);                  //风扇启动温度
  E_system_protect_TEM                          = E_system_fan_fanOpen_TEM + sizeof(unsigned char);                     //系统保护温度
  E_system_enable_OTA                           = E_system_protect_TEM + sizeof(unsigned char);                         //OTA开关，0-关，1-开
  E_system_output_state                         = E_system_enable_OTA + sizeof(unsigned char);                          //输出开关状态，0-开，1-关
  E_system_ina_resistor_1                       = E_system_output_state + sizeof(unsigned char);                        //输入采样电阻
  E_system_ina_resistor_2                       = E_system_ina_resistor_1 + sizeof(float);                              //电池采样电阻
  E_system_ina_resistor_3                       = E_system_ina_resistor_2 + sizeof(float);                              //输出采样电阻
  E_mqtt_server_port                            = E_system_ina_resistor_3 + sizeof(float);                              //MQTT服务端口号
  E_system_uart_print_state                     = E_mqtt_server_port + sizeof(int);                                     //串口输出状态信息
  E_wifi_ssid_size                              = E_system_uart_print_state + sizeof(unsigned char);                    //WIFI名称长度
  E_wifi_psd_size                               = E_wifi_ssid_size + sizeof(unsigned char);                             //WIFI密码长度
  E_blinker_auth_size                           = E_wifi_psd_size + sizeof(unsigned char);                              //Blinker密钥长度
  E_mqtt_server_add_size                        = E_blinker_auth_size + sizeof(unsigned char);                          //MQTT服务地址长度
  E_mqtt_usr_size                               = E_mqtt_server_add_size + sizeof(unsigned char);                       //MQTT用户名长度
  E_mqtt_psd_size                               = E_mqtt_usr_size + sizeof(unsigned char);                              //MQTT密码长度
  E_system_ota_usr_size                         = E_mqtt_psd_size + sizeof(unsigned char);                              //OTA账号长度
  E_system_ota_psd_size                         = E_system_ota_usr_size + sizeof(unsigned char);                        //OTA密码长度
  Serial.print(F("EEPROM usual used:"));
  Serial.println(E_system_ota_usr_size + sizeof(unsigned char));
  switch(rcd){
    case 0:
      defaultSize();
      break;
    case 1:
      readSizeFromEEPROM();
      break;
    case 2:
      calSizeFromVar();
      break;
  }
  E_wifi_ssid                                   = E_system_ota_psd_size + sizeof(unsigned char);                        //wifi名称地址
  E_wifi_psd                                    = E_wifi_ssid + wifi_ssid_size;                                         //wifi密码地址
  E_blinker_auth                                = E_wifi_psd + wifi_psd_size;                                           //Bliner密钥
  E_mqtt_server_add                             = E_blinker_auth + blinker_auth_size;                                   //MQTT服务地址
  E_mqtt_usr                                    = E_mqtt_server_add + mqtt_server_add_size;                             //MQTT用户名地址
  E_mqtt_psd                                    = E_mqtt_usr + mqtt_usr_size;                                           //MQTT密码地址
  E_system_ota_usr                              = E_mqtt_psd + mqtt_psd_size;                                           //OTA账号地址
  E_system_ota_psd                              = E_system_ota_usr + system_ota_usr_size;                               //OTA密码地址
  E_system_bat_fullv                            = E_system_ota_psd + system_ota_psd_size;                               //电池满电电压
  E_check_code                                  = E_system_bat_fullv + sizeof(float);                                   //检验码地址放在最后
  Serial.print(F("EEPROM all used:"));
  Serial.println(E_check_code + sizeof(unsigned char));
}
//从存档中读取String型数据地址
void readSizeFromEEPROM(){                // 1
  //计算String型存档地址
  EEPROM.begin(EEPROM_SIZE);
  wifi_ssid_size                               = EEPROM.readUChar(E_wifi_ssid_size);                   //wifi名称长度地址
  wifi_psd_size                                = EEPROM.readUChar(E_wifi_psd_size);                    //wifi密码长度地址
  blinker_auth_size                            = EEPROM.readUChar(E_blinker_auth_size);                //Bliner密钥长度
  mqtt_server_add_size                         = EEPROM.readUChar(E_mqtt_server_add_size);             //MQTT服务地址长度
  mqtt_usr_size                                = EEPROM.readUChar(E_mqtt_usr_size);                    //MQTT用户名长度地址
  mqtt_psd_size                                = EEPROM.readUChar(E_mqtt_psd_size);                    //MQTT密码长度地址
  system_ota_usr_size                          = EEPROM.readUChar(E_system_ota_usr_size);              //OTA用户名长度地址
  system_ota_psd_size                          = EEPROM.readUChar(E_system_ota_psd_size);              //OTA密码长度
  EEPROM.end();
}
//从变量中计算String型变量的长度
void calSizeFromVar(){                   // 2
  wifi_ssid_size                               = wifi_ssid.length() + 1;
  wifi_psd_size                                = wifi_psd.length() + 1;
  blinker_auth_size                            = blinker_auth.length() + 1;
  mqtt_server_add_size                         = mqtt_server_add.length() + 1;
  mqtt_usr_size                                = mqtt_usr.length() + 1;
  mqtt_psd_size                                = mqtt_psd.length() + 1;
  system_ota_usr_size                          = system_ota_usr.length() + 1;
  system_ota_psd_size                          = system_ota_psd.length() + 1;
}
//计算String型变量默认长度
void defaultSize(){                       //  0
  wifi_ssid_size                               = 1;
  wifi_psd_size                                = 1;
  blinker_auth_size                            = 1;
  mqtt_server_add_size                         = 1;
  mqtt_usr_size                                = 1;
  mqtt_psd_size                                = 1;
  system_ota_usr_size                          = 6;                //默认admin
  system_ota_psd_size                          = 9;                //默认mppt3232
}
//出厂默认设置
void FactoryReset() {
  refreshAddress(0);
  EEPROM.begin(EEPROM_SIZE);
  //默认参数
  EEPROM.writeFloat(E_output_current_limit, 1);                                              //输出电流限制
  EEPROM.writeFloat(E_system_bat_maxv, 12.6);                                                //电池最大电压
  EEPROM.writeFloat(E_system_bat_minv, 7.5);                                                 //电池最小电压
  EEPROM.writeFloat(E_system_bat_protectv, 9);                                               //电池保护电压
  EEPROM.writeFloat(E_system_bat_current_limit, 1);                                          //电池充电及输出电流限制
  EEPROM.writeUChar(E_system_internet_mode, 0);                                              //0-离线模式，1-MQTT模式，2-Blinker模式
  EEPROM.writeUChar(E_system_output_control_mode, 0);                                        //0-普通模式，1-光控模式，2-光控+时控
  EEPROM.writeUChar(E_system_output_optical_control_time, 6);                                //光控+时控时打开时间
  EEPROM.writeUChar(E_system_lcd_backlight_time, 0);                                         //0-常开，1-3分钟，2-5分钟，3-10分钟，4-15分钟，5-30分钟
  EEPROM.writeUChar(E_system_fan_fanOpen_TEM, 40);                                           //风扇启动温度
  EEPROM.writeUChar(E_system_protect_TEM, 90);                                               //系统保护温度
  EEPROM.writeUChar(E_system_enable_OTA, 0);                                                 //OTA开关，0-关，1-开
  EEPROM.writeUChar(E_system_output_state, 1);                                               //输出开关状态，0-开，1-关
  EEPROM.writeFloat(E_system_ina_resistor_1, 0.002);                                         //输入采样电阻 默认0.002
  EEPROM.writeFloat(E_system_ina_resistor_2, 0.002);                                         //电池采样电阻 默认0.002
  EEPROM.writeFloat(E_system_ina_resistor_3, 0.002);                                         //输出采样电阻 默认0.002
  EEPROM.writeInt(E_mqtt_server_port, 1883);                                                 //MQTT服务端口地址
  EEPROM.writeUChar(E_system_uart_print_state, 0);                                           //串口输出工作状态 0-关 1-开
  EEPROM.writeUChar(E_wifi_ssid_size, wifi_ssid_size);                                       //wifi名称长度
  EEPROM.writeUChar(E_wifi_psd_size, wifi_psd_size);                                         //wifi名称长度
  EEPROM.writeUChar(E_blinker_auth_size, blinker_auth_size);                                 //Blinker密钥长度
  EEPROM.writeUChar(E_mqtt_server_add_size, mqtt_server_add_size);                           //MQTT地址长度
  EEPROM.writeUChar(E_mqtt_usr_size, mqtt_usr_size);                                         //MQTT用户名长度
  EEPROM.writeUChar(E_mqtt_psd_size, mqtt_psd_size);                                         //MQTT密码长度
  EEPROM.writeUChar(E_system_ota_usr_size, system_ota_usr_size);                             //OTA账户长度
  EEPROM.writeUChar(E_system_ota_psd_size, system_ota_psd_size);                             //OTA密码长度
  EEPROM.writeString(E_wifi_ssid, "");                                                       //wifi名称
  EEPROM.writeString(E_wifi_psd, "");                                                        //wifi密码
  EEPROM.writeString(E_blinker_auth, "");                                                    //Blinker密钥
  EEPROM.writeString(E_mqtt_server_add, "");                                                 //MQTT地址
  EEPROM.writeString(E_mqtt_usr, "");                                                        //MQTT用户名
  EEPROM.writeString(E_mqtt_psd, "");                                                        //MQTT密码
  EEPROM.writeString(E_system_ota_usr, "admin");                                             //OTA用户名
  EEPROM.writeString(E_system_ota_psd, "mppt3232");                                          //OTA密码
  EEPROM.writeFloat(E_system_bat_fullv, 12.6);                                               //默认电池满电电压
  EEPROM.writeUChar(E_check_code, eeprom_check_code);                                        //检验码
  //保存到flash
  EEPROM.commit(); 
  EEPROM.end();
}
//读取设置
void LoadSettings(){
  refreshAddress(1);
  EEPROM.begin(EEPROM_SIZE);
  //检验存档，如果不正确，写入出厂设置
  if(EEPROM.readUChar(E_check_code) != eeprom_check_code){
    EEPROM.end();
    FactoryReset();
    ESP.restart();
  }
  //读取存档
  output_current_limit                           =  EEPROM.readFloat(E_output_current_limit);                                 //输出电流限制
  system_bat_maxv                                =  EEPROM.readFloat(E_system_bat_maxv);                                      //电池最大电压
  system_bat_minv                                =  EEPROM.readFloat(E_system_bat_minv);                                      //电池最小电压
  system_bat_protectv                            =  EEPROM.readFloat(E_system_bat_protectv);                                  //电池保护电压
  system_bat_current_limit                       =  EEPROM.readFloat(E_system_bat_current_limit);                             //电池充电及输出电流限制
  system_internet_mode                           =  EEPROM.readUChar(E_system_internet_mode);                                 //0-离线模式，1-MQTT模式，2-Blinker模式
  system_output_control_mode                     =  EEPROM.readUChar(E_system_output_control_mode);                           //0-普通模式，1-光控模式，2-光控+时控
  system_output_optical_control_time             =  EEPROM.readUChar(E_system_output_optical_control_time);                   //光控+时控时打开时间
  system_lcd_backlight_time                      =  EEPROM.readUChar(E_system_lcd_backlight_time);                            //0-常开，1-3分钟，2-5分钟，3-10分钟，4-15分钟，5-30分钟
  system_fan_fanOpen_TEM                         =  EEPROM.readUChar(E_system_fan_fanOpen_TEM);                               //风扇启动温度
  system_protect_TEM                             =  EEPROM.readUChar(E_system_protect_TEM);                                   //系统保护温度
  system_enable_OTA                              =  EEPROM.readUChar(E_system_enable_OTA);                                    //OTA开关，0-关，1-开
  system_output_state                            =  EEPROM.readUChar(E_system_output_state);                                  //输出开关状态，0-开，1-关
  system_ina_resistor_1                          =  EEPROM.readFloat(E_system_ina_resistor_1);                                //输入采样电阻
  system_ina_resistor_2                          =  EEPROM.readFloat(E_system_ina_resistor_2);                                //电池采样电阻
  system_ina_resistor_3                          =  EEPROM.readFloat(E_system_ina_resistor_3);                                //输出采样电阻
  mqtt_server_port                               =  EEPROM.readInt(E_mqtt_server_port);                                       //MQTT服务端口
  system_uart_print_state                        =  EEPROM.readUChar(E_system_uart_print_state);                              //串口输出状态
  wifi_ssid                                      =  EEPROM.readString(E_wifi_ssid);                                           //wifi名称
  wifi_psd                                       =  EEPROM.readString(E_wifi_psd);                                            //wifi密码
  blinker_auth                                   =  EEPROM.readString(E_blinker_auth);                                        //Blinker密钥
  mqtt_server_add                                =  EEPROM.readString(E_mqtt_server_add);                                     //MQTT地址
  mqtt_usr                                       =  EEPROM.readString(E_mqtt_usr);                                            //MQTT用户名
  mqtt_psd                                       =  EEPROM.readString(E_mqtt_psd);                                            //MQTT密码
  system_ota_usr                                 =  EEPROM.readString(E_system_ota_usr);                                      //OTA账号
  system_ota_psd                                 =  EEPROM.readString(E_system_ota_psd);                                      //OTA密码
  system_bat_fullv                               =  EEPROM.readFloat(E_system_bat_fullv);                                     //电池满电电压
  EEPROM.end();
}
//写入设置
void SaveSettings(){
  refreshAddress(2);
  EEPROM.begin(EEPROM_SIZE);
  //设置内容
  EEPROM.writeFloat(E_output_current_limit, output_current_limit);                                             //输出电流限制
  EEPROM.writeFloat(E_system_bat_maxv, system_bat_maxv);                                                       //电池最大电压
  EEPROM.writeFloat(E_system_bat_minv, system_bat_minv);                                                       //电池最小电压
  EEPROM.writeFloat(E_system_bat_protectv, system_bat_protectv);                                               //电池保护电压
  EEPROM.writeFloat(E_system_bat_current_limit, system_bat_current_limit);                                     //电池充电及输出电流限制
  EEPROM.writeUChar(E_system_internet_mode, system_internet_mode);                                             //0-离线模式，1-MQTT模式，2-Blinker模式
  EEPROM.writeUChar(E_system_output_control_mode, system_output_control_mode);                                 //0-普通模式，1-光控模式，2-光控+时控
  EEPROM.writeUChar(E_system_output_optical_control_time, system_output_optical_control_time);                 //光控+时控时打开时间
  EEPROM.writeUChar(E_system_lcd_backlight_time, system_lcd_backlight_time);                                   //0-常开，1-3分钟，2-5分钟，3-10分钟，4-15分钟，5-30分钟
  EEPROM.writeUChar(E_system_fan_fanOpen_TEM, system_fan_fanOpen_TEM);                                         //风扇启动温度
  EEPROM.writeUChar(E_system_protect_TEM, system_protect_TEM);                                                 //系统保护温度
  EEPROM.writeUChar(E_system_enable_OTA, system_enable_OTA);                                                   //OTA开关，0-关，1-开
  EEPROM.writeUChar(E_system_output_state, system_output_state);                                               //输出开关状态，0-开，1-关
  EEPROM.writeFloat(E_system_ina_resistor_1, system_ina_resistor_1);                                           //输入采样电阻
  EEPROM.writeFloat(E_system_ina_resistor_1, system_ina_resistor_2);                                           //输入采样电阻
  EEPROM.writeFloat(E_system_ina_resistor_1, system_ina_resistor_3);                                           //输入采样电阻
  EEPROM.writeInt(E_mqtt_server_port, mqtt_server_port);                                                       //MQTT服务端口
  EEPROM.writeUChar(E_system_uart_print_state, system_uart_print_state);                                       //串口输出状态 0-关 1-开
  EEPROM.writeUChar(E_wifi_ssid_size, wifi_ssid_size);                                                         //wifi名称长度
  EEPROM.writeUChar(E_wifi_psd_size, wifi_psd_size);                                                           //wifi名称长度
  EEPROM.writeUChar(E_blinker_auth_size, blinker_auth_size);                                                   //Blinker密钥长度
  EEPROM.writeUChar(E_mqtt_server_add_size, mqtt_server_add_size);                                             //MQTT地址长度
  EEPROM.writeUChar(E_mqtt_usr_size, mqtt_usr_size);                                                           //MQTT用户名长度
  EEPROM.writeUChar(E_mqtt_psd_size, mqtt_psd_size);                                                           //MQTT密码长度
  EEPROM.writeUChar(E_system_ota_usr_size, system_ota_usr_size);                                               //OTA账号长度
  EEPROM.writeUChar(E_system_ota_psd_size, system_ota_psd_size);                                               //OTA密码长度
  EEPROM.writeString(E_wifi_ssid, wifi_ssid);                                                                  //wifi名称
  EEPROM.writeString(E_wifi_psd, wifi_psd);                                                                    //wifi密码
  EEPROM.writeString(E_blinker_auth, blinker_auth);                                                            //Blinker密钥
  EEPROM.writeString(E_mqtt_server_add, mqtt_server_add);                                                      //MQTT地址
  EEPROM.writeString(E_mqtt_usr, mqtt_usr);                                                                    //MQTT用户名
  EEPROM.writeString(E_mqtt_psd, mqtt_psd);                                                                    //MQTT密码
  EEPROM.writeString(E_system_ota_usr, system_ota_usr);                                                        //OTA账号
  EEPROM.writeString(E_system_ota_psd, system_ota_psd);                                                        //OTA密码
  EEPROM.writeFloat(E_system_bat_fullv, system_bat_fullv);                                                     //满电电压
  EEPROM.writeUChar(E_check_code, eeprom_check_code);                                                          //检验码
  //保存到flash
  EEPROM.commit(); 
  EEPROM.end();
}

//系统运行数据存储地址
int E_store_in_kwh                 =  EEPROM_SIZE - sizeof(float);                                         //累计发电量地址
int E_store_bat_kwh                =  E_store_in_kwh - sizeof(float);                                      //累计电池电量地址
int E_store_out_kwh                =  E_store_bat_kwh - sizeof(float);                                     //累计输出电量地址
int E_system_power_meter_in        =  E_store_out_kwh - sizeof(float);                                     //日输入电量累计，单位wh
int E_system_power_meter_bat       =  E_system_power_meter_in - sizeof(float);                             //日电池电量累计，单位wh
int E_system_power_meter_out       =  E_system_power_meter_bat - sizeof(float);                            //日输出电量累计，单位wh
int E_check_code_2                 =  E_system_power_meter_out - sizeof(unsigned char);                    //检验码地址

//系统运行数据存储
void store_sys_data(){
  EEPROM.begin(EEPROM_SIZE);
  EEPROM.writeUChar(E_check_code_2, eeprom_check_code);
  EEPROM.writeFloat(E_system_power_meter_out, system_power_meter_out);
  EEPROM.writeFloat(E_system_power_meter_bat, system_power_meter_bat);
  EEPROM.writeFloat(E_system_power_meter_in, system_power_meter_in);
  EEPROM.writeFloat(E_store_out_kwh, store_out_kwh);
  EEPROM.writeFloat(E_store_bat_kwh, store_bat_kwh);
  EEPROM.writeFloat(E_store_in_kwh, store_in_kwh);
  EEPROM.end();
}
//系统运行数据读取
void load_sys_data(){
  EEPROM.begin(EEPROM_SIZE);
  if(EEPROM.readUChar(E_check_code_2) != eeprom_check_code){
    //默认值
    store_in_kwh              = 0.0;
    store_bat_kwh             = 0.0;
    store_out_kwh             = 0.0; 
    system_power_meter_in     = 0.0;
    system_power_meter_bat    = 0.0;
    system_power_meter_out    = 0.0;
  }else{
    //读取存档
    store_in_kwh               = EEPROM.readFloat(E_store_in_kwh);
    store_bat_kwh              = EEPROM.readFloat(E_store_bat_kwh);
    store_out_kwh              = EEPROM.readFloat(E_store_out_kwh);
    system_power_meter_in      = EEPROM.readFloat(E_system_power_meter_in);
    system_power_meter_bat     = EEPROM.readFloat(E_system_power_meter_bat);
    system_power_meter_out     = EEPROM.readFloat(E_system_power_meter_out);
  }
  EEPROM.end();
}
